package com.zf.yichat.controller.sys;

import com.zf.yichat.controller.BaseController;
import com.zf.yichat.service.AgreementService;
import com.zf.yichat.service.config.RedisService;
import com.zf.yichat.utils.response.FsResponse;
import com.zf.yichat.utils.response.FsResponseGen;
import com.zf.yichat.vo.DictKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 隐私政策
 */
@Controller
public class PrivacyPolicyController extends BaseController {

    @Autowired
    private RedisService redisService;

    @Autowired
    private AgreementService agreementService;

    @RequestMapping("privacy/index")
    public String index() {
        getRequest().setAttribute("content", redisService.getVal(DictKey.privacy_policy.name()));
        return "sys/privacy/save";
    }

    @PostMapping("privacy/save")
    @ResponseBody
    public FsResponse save(String content) {
        redisService.setVal(DictKey.privacy_policy.name(), content);
        agreementService.saveAgreement("privacy", content);
        return FsResponseGen.success();
    }

    @GetMapping("privacy/show")
    public String indexs() {
        getRequest().setAttribute("content", redisService.getVal(DictKey.privacy_policy.name()));
        return "sys/privacy/index";
    }
}
